import { defineConfig } from "vite";
import { resolve } from "path";
import uni from "@dcloudio/vite-plugin-uni";

const pathResolve = (dir: string): any => {
  return resolve(__dirname, ".", dir);
};

const alias: Record<string, string> = {
  "@/": pathResolve("./src/"),
};

export default defineConfig({
  plugins: [uni()],
  server: {
    proxy: {
      "/stage-api": {
        target: "https://kukecloud-test.tyyk99.com/stage-api", // 目标接口地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/stage-api/, ""),
      },
      "/dev": {
        target: "https://kkteacher-crm.kukewang.com/dev", // 目标接口地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev/, ""),
      },
      "/stage-tenant": {
        target: "https://kukecloud-test.tyyk99.com/stage-tenant", // 目标接口地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/stage-tenant/, ""),
      },
    },
  },
  define: {
    "process.env": {},
  },
  resolve: {
    alias,
  },
  build: {
    rollupOptions: {
      external: ["md5"],
    },
  },
});
